
<%@ page import="sedh.project.Servico"%>
<%@ page import="sedh.project.AlocadorMunSer"%>
<html>
<head>

<modalbox:modalIncludes />

<script type="text/javascript">
	    function ChangeColor(tableRow, highLight)
	    {
	    if (highLight)
	    {
	      tableRow.style.backgroundColor = '#CCCCCC';
	    }
	    else
	    {
	      tableRow.style.backgroundColor = '#FFFFFF';
	    }
	  }
	
	  function DoNav(theUrl)
	  {
	  document.location.href = "/SEDH-PROJECT/servico/list/"+theUrl;
	  }

	  function EditSer(id) {
		  document.location.href = "/SEDH-PROJECT/servico/edit/"+id;
	   }
	  function EditSerMun(id) {
		  document.location.href = "/SEDH-PROJECT/alocadorMunSer/edit/"+id;
	   }
	  
	  function createLink(theUrl)
	  {
	  document.location.href = "?mun="+theUrl;
	  }
	  function showSpinner(visible) {
	         $('spinner').style.display = visible ? "inline" : "none";
	     }
	     Ajax.Responders.register({
	     onLoading: function() {
	           showSpinner(true);
	     },
	     onComplete: function() {
	     if(!Ajax.activeRequestCount) showSpinner(false);
	     }
	   });

	  </script>
<g:render template="/header" />
</head>

<body>
	<g:render template="/informationBar" />

	<g:render template="/menu" />

	<div class="body">

		<div class="searchDivService">
			<h1>Pesquisa de Servico:</h1>
			<g:remoteField class="searchBox" name="search"
				paramName="searchvalue" update="searchresult" value=""
				url="[controller:'servico', action:'searchServico']"
				onLoading="showSpinner(true);" onComplete="showSpinner(false);">
			</g:remoteField>
		</div>
		<div class="servicoList">
			<g:render template="searchResult" var="searchresults"
				bean="${servicoInstanceList}" />

		</div>
		<div class="servicoList">


			<h1>Informacoes dos Servicos:</h1>
			<h3>Nome:</h3>
			${fieldValue(bean: servicoInstance, field: "nome")}
			<g:if
				test="${fieldValue(bean: servicoInstance, field: 'nome').toString().equals('') }">
			</g:if>
			<g:else>
					<a href="${createLink(controller:'alocadorMunSer',action:'createbyser',params:[serv:fieldValue(bean: servicoInstance, field: "nome").toString()] )}" >Alocar para Municipio</a>
			</g:else>
			</br>
			<h3>Descricao:</h3>
			${fieldValue(bean: servicoInstance, field: "descricao")}</br>
			<h3>Municipios com esse servico:</h3>
			<g:if
				test="${fieldValue(bean: alocMunSerInstance, field: 'municipio').toString().equals('') }">
				Nenhum Municipio Encontrado
			</g:if>
			<g:else>
				<g:each in="${alocMunSerInstance}" status="i" var="alocAtual">
					<g:if
						test="${fieldValue(bean: servicoInstance, field: 'nome').toString().equals(fieldValue(bean: alocAtual, field: 'servico').toString())}">
						<a href="#" ondblclick="EditSerMun('${fieldValue(bean: alocAtual, field: 'id')}')"
							onclick="createLink('${fieldValue(bean: alocAtual, field: 'id')}');">
							${fieldValue(bean: alocAtual, field: 'municipio')}
						</a>
						<br>
					</g:if>
				</g:each>
			</g:else>
		</div>
		<div class="servicoList">
			<h1>Dados Gerais do Municipio:</h1>
			<g:each in="${alocMunSerInstance}" status="i" var="alocAtual">
				<g:if
					test="${fieldValue(bean: alocAtual, field: 'id').toString().equals(mun)}">
					<h3>Responsavel:</h3>
					${fieldValue(bean: alocAtual, field: 'responsavel')}<br>
					<h3>Telefone:</h3>
					${fieldValue(bean: alocAtual, field: 'telefone')}
					</br>
					<h3>Numero de Familias:</h3>
					${fieldValue(bean: alocAtual, field: 'familias')}
					</br>
				</g:if>
			</g:each>

		</div>
	</div>
</body>
</html>
